package routers

import (
	"github.com/cy77cc/hioshop/controller"
	"github.com/cy77cc/hioshop/middleware"
	"github.com/gin-gonic/gin"
)

type ApiShop struct{}

func (s *ApiShop) InitShopApi(path string, router *gin.Engine) {
	showSettingHandler := controller.ShowSettingHandler{}
	shop := router.Group(path, middleware.JwtAuth(), middleware.LimitAccess())
	settings := shop.Group("/settings")
	{
		settings.GET("/showSettings", showSettingHandler.ShowSettings)
	}

	index := shop.Group("/index")
	indexHandler := controller.IndexHandler{}
	{
		index.GET("/appInfo", indexHandler.GetAppInfo)
	}

	auth := shop.Group("/auth", middleware.LoadEnv())
	authHandler := controller.AuthHandler{}
	{
		auth.POST("/loginByWeixin", authHandler.LoginByWeixin)
	}

	goods := shop.Group("/goods")
	goodsHandler := controller.GoodsHandler{}
	{
		goods.GET("/detail", goodsHandler.GetDetail)
		goods.GET("/list", goodsHandler.GetGoodsList)
	}

	cart := shop.Group("/cart")
	cartHandler := controller.CartHandler{}
	{
		cart.GET("/goodsCount", cartHandler.GetGoodsCount)
		cart.GET("/index", cartHandler.Index)
	}

	search := shop.Group("/search")
	searchHandler := controller.SearchHandler{}
	{
		search.GET("/index", searchHandler.Index)
	}

	catalog := shop.Group("/catalog")
	catalogHandler := controller.CatalogHandler{}
	{
		catalog.POST("/currentlist", catalogHandler.GetCurrentList)
		catalog.GET("/current", catalogHandler.Current)
	}

	order := shop.Group("/order")
	orderHandler := controller.OrderHandler{}
	{
		order.GET("/orderCount", orderHandler.OrderCount)
		order.GET("/list", orderHandler.List)
	}

	setting := shop.Group("/settings")
	settingHandler := controller.SettingHandler{}
	{
		setting.GET("/userDetail", settingHandler.GetUserDetail)
		setting.POST("/save", settingHandler.SaveUserInfo)
	}

	upload := shop.Group("/upload", middleware.LoadEnv())
	uploadHandler := controller.UploadHandler{}
	{
		upload.POST("/uploadAvatar", uploadHandler.UploadAvatar)
	}

	region := shop.Group("/region")
	regionHandler := controller.RegionHandler{}
	{
		region.GET("/list", regionHandler.GetList)
	}

	address := shop.Group("/address")
	addressHandler := controller.AddressHandler{}
	{
		address.GET("/getAddress", addressHandler.GetAddress)
		address.GET("/getAddresses", addressHandler.GetAddress)
		address.POST("/saveAddress", addressHandler.SaveAddress)
		address.GET("/addressDetail", addressHandler.GetAddressDetail)
		address.POST("/deleteAddress", addressHandler.DeleteAddress)
	}
}
